package com.trkj.service.lzs;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.lzs.SalaryAccountDao;
import com.trkj.dao.lzs.StaffDAO;
import com.trkj.pojo.Salary;
import com.trkj.pojo.SalaryAccount;
import com.trkj.pojo.StaffInformation;
import com.trkj.service.ServiceException;
import com.trkj.vo.emp_payVO;


@Service
@Transactional(rollbackFor=Exception.class)
public class Emp_payService {
	@Autowired
	private StaffDAO staffDAO;
	@Autowired
	private SalaryAccountDao saDao;
	/**
	 *多表查询所有
	 * @return
	 */
	public List<emp_payVO> selcet_emp_pay(){
		List<emp_payVO> vo = new ArrayList();
		List<Object[]> obj= staffDAO.find_emp_pay();
		for (Object[] objects : obj) {
			emp_payVO vof = new emp_payVO();
			StaffInformation s  = (StaffInformation) objects[0];
			SalaryAccount Sal  = (SalaryAccount) objects[1];
			if(Sal!=null){
				vof.setAccountName(Sal.getAccountName());
				vof.setAccountStartdate(Sal.getAccountStartdate());
				vof.setAccountEnddate(Sal.getAccountEnddate());
			}
				vof.setStainId(s.getStainId());
				vof.setStainName(s.getStainName());
				vo.add(vof);
		}
		return vo;
	}
	/**
	 * 模糊查询
	 * @param text
	 * @return
	 */
	public List<emp_payVO> select_find_idname(String text){
		List<emp_payVO> vo = new ArrayList();
		List<Object[]> obj= staffDAO.query_By_idorname("%"+text+"%");
		for (Object[] objects : obj) {
			emp_payVO vof = new emp_payVO();  
			StaffInformation s  = (StaffInformation) objects[0];
			SalaryAccount Sal  = (SalaryAccount) objects[1];
			if(Sal!=null){
				vof.setAccountName(Sal.getAccountName());
				vof.setAccountStartdate(Sal.getAccountStartdate());
				vof.setAccountEnddate(Sal.getAccountEnddate());
			}
				vof.setStainId(s.getStainId());
				vof.setStainName(s.getStainName());
				vo.add(vof);
		}
		return vo;
	}
	/**
	 * 查询员工表
	 * @return
	 */
	public List<StaffInformation> selcet_StaffInformation(){
		return (List<StaffInformation>) staffDAO.findAll();
	}
	/**
	 * 新增
	 * @param stainId
	 * @param accountId
	 * @param startDate
	 * @param endDate
	 */
	public void insert_emp_pay(StaffInformation staff,Long accountId){
		try {
			SalaryAccount sa = saDao.findOne(accountId);
			staff.setSalaryAccount(sa);
			staffDAO.save(staff);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
}
